<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>eForm example</title>
		<style type="text/css">

*{
font-family:arial, helvetica, sans-serif;
font-size:10pt;
border-width:1px;
border-color:#003399;
}

body{
background-color:#a4d1f9;
}

h1, h2, h3{
margin-bottom:0;
color:#003399;
}

h1{
margin-top:0;
margin-bottom:20px;
font-size:20pt;
text-align:center;
border-bottom-style:solid;
border-color:#e78900;
}

h2{
font-size:12pt;
}

hr{
color:#ffffff;
border-style:none none solid none;
border-color:#e78900;
}

p{
margin-top:0;
}

ul{
margin:0 0 0 10px;
padding:0;
list-style-type:square;
}

code{
font-family:monospace;
color:#666666;
}

a{
color:#e78900;
text-decoration:none;
}

a:hover{
border-bottom-style:dashed;
}

#qe_logo{
float:right;
margin:0 57px 20px 57px;
}

#qe_toc{
width:200px;
margin:0 0 20px 20px;
padding:20px;
float:right;
clear:right;
border-style:solid;
background-color:#eaf9ff;
}

#qe_toc h1{
margin-top:0;
font-size:12pt;
text-align:center;
}

div.qe_box{
margin:30px;
padding:30px;
border-style:solid;
background-color:#ffffff;
}

div.qe_level_2{
margin-left:20px;
margin-right:20px;
}

.qe_salutation{
margin-left:30px;
}

.qe_signature{
font-family:cursive;
font-size:14pt;
}

.qe_param_list li{
	margin:2px;
	color:#333;
}
.qe_param_list li strong{
	color:#036;
	font-size:1.02em
}
.new{
	color:#c00;
	font-weight:bold;
}
.codeblock{
	margin:10px 0;
	padding:5px;
	background:#eaeaea;
	border:1px solid #999;
	font-family:monospace;
	white-space: nowrap;
	overflow: auto;
	max-height: 24em;
	clear:right;
}

.qe_param_list li{
	margin:2px;
	color:#333;
}
.qe_param_list li strong{
	color:#036;
	font-size:1.02em
}
.new{
	color:#c00;
	font-weight:bold;
}
.style1 {font-size: smaller}
    </style>


</head>

<body>
<div class="qe_box">
<h1>eForm - Examples</h1><img id="qe_logo" src="logo.png" alt="logo" />

		<div id="qe_toc">
			<h1>Index</h1>
				<ul>
					<li><a href="eform.htm#top">Main index</a></li>
					<li><a href="eform_examples.htm">Examples</a>
					<ul>
						<li><a href="eform_examples.htm#top">Feedback Form</a></li>
						<li><a href="eform_example_multiple_forms.htm">Multiple forms</a></li>
						<li><a href="eform_example_events.htm">eForm events</a></li>
					</ul>
					</li>
				</ul>
		</div>

<div class='qe_level_1'>
<h2>Creating a general purpose feedback form</h2>
<p>For this example we're creating a feedback form where web site users can send feedback to three different departments or email addresses. This is achieved trough the subject selectbox which will be used by eForm to select the correct email address. All fields will be required and to avoid any spamming by automated submit scripts were also adding a <abbr title="Completely Automated Public Turing Test to Tell Computers and Humans Apart">CAPTCHA</abbr> field. When users succesfully have submitted the form they will be presented with a thank you message which includes a copy of what the user submitted.</p>

<p>To achieve this we firstly need to create the following '<em>templates</em>' either as chunks or in (unplished) MODx documents.</p>
<ul>
<li><a href="#html">The HTML Form</a></li>
<li><a href="#email">The body of the email</a></li>
<li><a href="#thankyou">The thank you page</a></li>
</ul>
<p><br />And offcourse we need to place the <a href="#snippetcall">snippet call</a> on our feedback page. The form will look something like this (after some styling)</p>

</div>
<div class='qe_level_2'>
<h3>The form</h3>
<p><img src="form1.gif" width="404" height="317" alt="Exampel form" border="1" title="" /></p>
<a id="html" name="html"></a>
<h3>The HTML Form Template</h3>
<p>For this example we will create a chunk called '<em>eFeedBackForm</em>' and copy and paste the following form</p>
	<div class='codeblock'>
	[+validationmessage+]<br />
	&lt;form method=&quot;post&quot; action=&quot;[~[*id*]~]&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&lt;input type=&quot;hidden&quot; name=&quot;formid&quot; value=&quot;feedbackForm&quot; /&gt;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label accesskey=&quot;n&quot; for=&quot;Name&quot;&gt;Your Name&lt;/label&gt;<br />
	&nbsp;&nbsp; &nbsp;&lt;input type=&quot;text&quot; name=&quot;Name&quot; maxlength=&quot;60&quot; eform=&quot;Your
	Name::1:Expected at least two words:#REGEX /^\w+\s\w+/i&quot; /&gt;&lt;/p&gt;<br />
	<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label accesskey=&quot;e&quot; for=&quot;email&quot;&gt;Your Email Address&lt;/label&gt;<br />&nbsp;&nbsp; &nbsp;&lt;input type=&quot;text&quot; name=&quot;email&quot; size=&quot;40&quot; maxlength=&quot;40&quot; eform=&quot;Your Email Address:email:1&quot; /&gt;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label accesskey=&quot;s&quot; for=&quot;department&quot;&gt;Subject&lt;/label&gt;<br />&nbsp;&nbsp; &nbsp;&lt;select name=&quot;department&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;option value=&quot;1&quot;&gt;Website feedback&lt;/option&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;option value=&quot;2&quot;&gt;Support request&lt;/option&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;option value=&quot;3&quot;&gt;Feature request&lt;/option&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/select&gt;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label accesskey=&quot;c&quot; for=&quot;comments&quot;&gt;Comments&lt;/label&gt;<br />&nbsp;&nbsp; &nbsp;&lt;textarea cols=&quot;40&quot; rows=&quot;10&quot; name=&quot;comments&quot; eform=&quot;Comments:html:1&quot;&gt;&lt;/textarea&gt;&lt;/p&gt;<br /><br />&nbsp;&nbsp; &nbsp;&lt;p&gt;<br />&nbsp;&nbsp; &nbsp;Please enter the &nbsp;&nbsp; &nbsp;anti spam code below:&lt;br /&gt;<br />&nbsp;&nbsp; &nbsp;&lt;img src=&quot;[+verimageurl+]&quot; alt=&quot;verification code&quot; border=&quot;1&quot;/&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;<br />&nbsp;&nbsp; &nbsp;&lt;label accesskey=&quot;c&quot; for=&quot;vericode&quot;&gt;code&lt;/label&gt;<br />&nbsp;&nbsp; &nbsp;&lt;input type=&quot;text&quot; name=&quot;vericode&quot; size=&quot;20&quot; /&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Send Feedback&quot;&gt;&lt;/p&gt;<br />&lt;/form&gt;	</div>
<a id="formid" name="formid"></a>
<p>A fairly straight forward html form with some placeholders for error messages and the vericode (CAPTCHA). Note the <code>formid</code> field. This hidden field is required so that eForm can recognize the form. We'll get back to that later at the <a href="#snippetcall">snippet call</a>.</p>
<p>The required fields have formatting and validations options set using the <code>eform</code> pseudo attribute (See the <a href="eform_validation.htm">form validation page</a> for details on setting values for the <code>eform</code> attribute) The eform attribute will be stripped from the form before it is sent to the browser.</p>
<p>The <code>[+validationmessage+]</code> placeholder will be filled with an error message if the form submit was unsuccesful. Below is an example message:</p>

<p style="color:red">Some errors were detected in your form:<br />
The following required field(s) are missing: Your Name, Comments<br />
Your Email Address is not a valid email address</p>

<p><strong>Note!</strong> In the above template we use a hidden field for the formid: <code>&lt;input type=&quot;hidden&quot; name=&quot;formid&quot; value=&quot;feedbackForm&quot; /&gt;</code><br />
If you are using eForm 1.4+ you can instead use the <strong>id</strong> attribute
of the form tag itself and leave out the hidden field: <code>&lt;form id=&quot;feedbackForm&quot; method=&quot;post&quot; action=&quot;[~[*id*]~]&quot;&gt;</code>.
Either way will work
</p>

<a id="email" name="email"></a>
<h3>The email template</h3>
<p>We'll create another chunk for the body of the email and call this one '<em>eFeedbackReport</em>'</p>
<div class='codeblock'>
&lt;p&gt;This is a response sent by [+name+] using the feedback form on the website. The details of the message follow below:&lt;/p&gt;<br />&lt;table&gt;<br />&lt;tr valign=&quot;top&quot;&gt;&lt;td&gt;Name:&lt;/td&gt;&lt;td&gt;[+name+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr valign=&quot;top&quot;&gt;&lt;td&gt;Email:&lt;/td&gt;&lt;td&gt;[+email+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr valign=&quot;top&quot;&gt;&lt;td&gt;comments:&lt;/td&gt;&lt;td&gt;[+comments+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;p&gt;You can use this link to reply: &lt;a href=&quot;mailto:[+email+]?subject=RE:[+subject+]&quot;&gt;[+email+]&lt;/a&gt;&lt;/p&gt;<br /><br />
</div>
<p>As you can see you can use HTML markup in your email. Using placeholders for each field we can populate the email with all information from the submitted form. Placeholders must have the same name as the name used for the from field.</p>
<a id="thankyou" name="thankyou"></a>
<h3>The Thank you message</h3>
<p>The same recipe... another chunk, called '<em>eFeedBackThanks</em>' this time</p>
<div class='codeblock'>
&lt;h3&gt;Thank you for your feedback&lt;/h3&gt;<br />&lt;p&gt;We know how you appreciate our ongoing efforts and thank you for your praise.<br />We will take any suggestions you may have made to heart and will endeavor to <br />respond to you in a timely manner.&nbsp; However as all office staff is attending<br />our 4 week annual company retreat, this year held in the Costa Del Sol, we ask<br />for your patience.&lt;/p&gt;<br />&lt;p&gt;Below is a copy of your message:&lt;/p&gt;<br />&lt;table&gt;<br />&lt;tr&gt;&lt;td&gt;Your name:&lt;/td&gt;&lt;td&gt;[+name+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr&gt;&lt;td&gt;Your email address&lt;/td&gt;&lt;td&gt;[+email+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr valign=&quot;top&quot;&gt;&lt;td&gt;Your comments&lt;/td&gt;&lt;td&gt;[+comments+]&lt;/td&gt;&lt;/tr&gt;<br />&lt;/table&gt;<br />
</div>

<p>The thank you template can be used to present the web site user with a more comprehensive follow up after thay have submitted the form and can contain the same placeholders as used in the report template.</p>

<a id="snippetcall" name="snippetcall"></a>
<h3>The Snippet call</h3>
<div class='codeblock'>
[!eForm? &formid=`feedbackForm` &to=`info@some.domain.com,support@some.domain.com,requests@some.domain.com` &tpl=`eFeedBackForm` &report=`eFeedbackReport` &thankyou=`eFeedbackThanks` &mailselector=`department` &vericode=`1` &subject=`Web site feedback`!]<br />
</div>
<p>You should have all paramters on one line but just to make things a bit more readable below is a slightly more verbose printout.</p>
<div class='codeblock'>
[!eForm?<br />
&nbsp;&nbsp;&formid=`feedbackForm` <br />
&nbsp;&nbsp;&to=`info@some.domain.com,support@some.domain.com,requests@some.domain.com` <br />
&nbsp;&nbsp;&tpl=`eFeedBackForm` <br />
&nbsp;&nbsp;&report=`eFeedbackReport` <br />
&nbsp;&nbsp;&thankyou=`eFeedbackThanks` <br />
&nbsp;&nbsp;&mailselector=`department` <br />
&nbsp;&nbsp;&vericode=`1` <br />
&nbsp;&nbsp;&subject=`Web site feedback`<br />
!]
</div>
<p>I'll go through them one by one</p>
<ul>
<li><code>&formid=`feedbackForm</code><br />
This tells eForm which form it should process. The form must contain a hidden <code>formid</code> field with the same value. (You did read that <a href="#formid">note</a> didn't you?)
</li>
<li><code>&to</code><br />
Here we have the three email addresses of which one can be selected in the form using the <code>department</code> select box. See the <code>&mailselector</code> below.
</li>
<li><code>&tpl</code><br />
The name of the chunk with the form template we created</li>
<li><code>&report</code><br />
The name of the chunk with the email template
</li>
<li><code>&thankyou</code><br />
Yes,... you guessed it.
</li>
<li><code>&mailselector</code><br />
This contains the name of the <code>department</code> field which we use to select the email address to use. Note the option values of the <code>department</code> select box in the form. They are 1,2 and 3. The value returned from this field will select one of the addresses we just declared in the <code>&to</code> parameter.1 will select the first address, 2 the second and so on.
</li>
<li><code>&vericode</code><br />
When you add the <code>&vericode=`1`</code> parameter to the snippet call eForm will replace the <code>[+verimageurl+]</code> placeholder in the form with a CAPTCHA generated image. On submitting the form the <code>vericode</code> field is then validated against the text displayed in the image.
</li>
<li><code>&subject</code><br />
This will be used as the subject of the email.
</li>
</ul>

<p><br /><strong>That's it,.. have fun.</strong></p>

<h3>Using chunks, snippets or documents for eForm templates</h3>
<p>Although we have been using chunks for this example you can just as easily
	use documentsor even snippets for each template.<br />
	In the case of a document
		you would pass the document id to eForm, for example <code>&tpl=`31`</code>. <span class="style1">(There is a catch however when you are using the tinyMCE editor. TinyMCE cleans
		HTML from what it considers invalid attributes and thus will strip the <code>eform</code> attribute
		from your form. If you want to place your form in a document instead of a chunk
		make sure you don't use the TinyMCE editor for that document.)<br />
		</span>Using a snippet as your template source gives you even more flexibility.
		You can dynamically create options and fields, however you must make sure
		that the snippet returns the same form template between form submits as otherwise
		eForm's validation code may incorrectly evaluate invalid values.<span class="style1"> If for instance
		you have a select box with the  options values 1,2 &amp; 3 (from a database for
		instance) at the first pass and when those values have changed to
		2,3 &amp; 4 by the time the form is submitted (and the template retrieved a
		second time with the changed values),  eform will see a submitted
		value of 1 as invalid...</span></p>
<p><em>There is a way to add the eform as a valid attribute to tinyMCE but you'll have to dig into the tinyMCE plugin code to do that. However that's beyond the scope of this article.</em></p>
<hr />
<p ><span class='qe_signature'>Jelle Jager</span><br />
AKA TobyL<br />
(and no,.. don't try to pronounce it)
</p>
</div>
</div>
</body>
</html>
